﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Demo2
{
    class Program
    {
        static void Main(string[] args)
        {
            Robot robot;
            while (true)
            {
                Console.WriteLine("1.炒菜，2.传菜");
                Console.WriteLine("请输入您的选择：");
                string s = Console.ReadLine();
                switch (s)
                {
                    case "1":
                        robot = Test("炒菜");
                        break;
                    case "2":
                        robot = Test("传菜");
                        break;
                    default:
                        Console.WriteLine("输入错误，请重新输入");
                        continue;
                }
                break;
            }
            robot.Working();
        }
        public static Robot Test(string s)
        {
            Robot robot = new CookRobot();

            if (s == "炒菜")
            {
               
                string[] fds = Enum.GetNames(typeof(Foods));
                Console.WriteLine("今天的菜单，输入数字选择：");

               
                for (int i = 0; i < fds.Length; i++)
                {
                    Console.WriteLine((i + 1) + "." + fds[i]);
                }
                int f;
                while (true)
                {
                    Console.WriteLine("请输入您的选择");
                    f = int.Parse(Console.ReadLine());
                    
                    if (f - 1 < fds.Length && f - 1 >= 0)
                    {
                        
                        break;
                    }
                    
                    else
                    {
                        Console.WriteLine("输入错误，请重新输入");
                    }
                }
                
                Foods fd = (Foods)Enum.Parse(typeof(Foods), fds[f - 1]);


                Console.WriteLine("请给机器人取个名");
                string name = Console.ReadLine();
                robot = new CookRobot(name, fd);
            }
            if (s == "传菜")
            {
                double realNum;

                while (true)
                {
                    Console.WriteLine("请输入机器人连续工作时长,");
                    string num = Console.ReadLine();
                    
                    bool res = double.TryParse(num, out realNum);
                    if (res)
                    {
                        break;
                    }
                    else
                    {
                        Console.WriteLine("输入错误，请重新输入");
                    }
                }
                Console.WriteLine("请给机器人取个名");
                string name = Console.ReadLine();

                robot = new DeliveryRobot(name, realNum);
            }

            return robot;
        }
    }
}
